package priv.mill.hdfs.impl;

import java.io.IOException;
import java.net.URI;

import org.apache.hadoop.fs.FileSystem;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

@Configuration
@ImportResource(locations = "classpath*:spring-hadoop.cfg.xml")
@ComponentScan
public class HadoopUtilSpringConfig {

	
	@Value("${hdfs.user}")
	String user;
	
	@Value("${hdfs.host}")
	String host;
	
	@Value("${hdfs.port}")
	String port;
	
	@Bean
	public FileSystem fileSystem() {
		System.out.println(user);
		org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
		FileSystem fs = null;
		try {
			System.setProperty("HADOOP_USER_NAME", user);
			fs = FileSystem.get(URI.create("hdfs://" + host + ":" + port), conf);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return fs;
	}

}
